package development.app;

import java.util.Vector;

import state.Clip;
import state.GameAlert;
import state.GameConstants;
import state.GameForm;
import state.GameGlobal;
import state.Graphics;
import state.Key;
import state.component.GameScrollBar;
import state.font.FontManager;
import state.font.ImageText;
import state.socket.DataPackage;
import state.socket.MapDataPackage;
import state.util.GameColor;
import state.util.GameStringUtils;
import state.util.Hashtable;
import state.util.NumberUtil;
import state.util.array.StringArray;
import development.Constants;
import development.DrawUtils;
import development.Global;
import development.bean.Category;
import development.group.FrmGroupBongDaXoSo;

public class FrmDanhSachNguoiChoi extends GameForm {

  public static final int PROGRAM_LIST_REQUEST = 600;
  public static final int PROGRAM_LIST_RESPONSE = 601;

  public static final int PHASE_LIST_REQUEST = 602;
  public static final int PHASE_LIST_RESPONSE = 603;

  public static final int VOTING_LIST_REQUEST = 604;
  public static final int VOTING_LIST_RESPONSE = 605;

  public static final int SEARCH_USER_REQUEST = 606;
  public static final int SEARCH_USER_RESPONSE = 607;

  public static final int VOTING_LIST_HISTORY_REQUEST = 608;
  public static final int VOTING_LIST_HISTORY_RESPONSE = 609;

  public static final int DAU_GIA_NGUOC_RESULT_REQUEST = 6010;
  public static final int DAU_GIA_NGUOC_RESULT_RESPONSE = 6011;

  private Vector categories;
  private String formType;
  private int categoryIndex;

  private ImageText text8;

  private int bottomParagraph;
  private int dy;
  private int defaultY;
  private int minTextY;

  private int currentAction;

  private Hashtable logAction = null;

  private final int DEFAULT_TEXT_X = 5;
  private GameScrollBar scrollBar;
  private Clip textView;

  private static GameForm singleton;
  private Hashtable parameters;

  private String title;

  private final String WAITING_MESSAGE = "Xin chờ trong giây lát...";

  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmDanhSachNguoiChoi();
    }
    return singleton;
  }

  public void init(Hashtable parameters1) {
    this.parameters = parameters1;
    title = "";
    text8 = FontManager.getFont(FontManager.FONT_SIZE_8);
    categories = new Vector();
    formType = "program";
    logAction = new Hashtable();
    currentAction = 1;

    textView = new Clip(DEFAULT_TEXT_X, dy, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT - dy - 10);
    scrollBar = new GameScrollBar(Constants.SCREEN_WIDTH - 5, 25, 5, Constants.SCREEN_HEIGHT - 50, textView, _manager);

    dy = DrawUtils.getTopBarHeight() + 1;
    if (parameters1 != null) {
      String requestType = (String) parameters1.get("RequestType");
      if (requestType.equals("FOOTBALL")) {
        Vector param = new Vector();
        param.addElement(requestType);
        param.addElement(Global.currentUser.getName());
        param.addElement(requestType);
        request(VOTING_LIST_HISTORY_REQUEST, param);
      } else if (requestType.equals("PHANG_ONLINE")) {
        Vector param = new Vector();
        param.addElement(requestType);
        param.addElement(Global.currentUser.getName());
        param.addElement(requestType);
        request(VOTING_LIST_HISTORY_REQUEST, param);
      } else if (requestType.equals("DAU_GIA_NGUOC")) {
        Vector param = new Vector();
        param.addElement(parameters1.get("phaseId"));
        param.addElement(Global.currentUser.getName());
        param.addElement(requestType);
        request(VOTING_LIST_HISTORY_REQUEST, param);
      }
    }
    _manager.enableTouchPad();
    DrawUtils.setBottomBar(_manager, null, null, "Trở về");
  }

  public void draw(Graphics g) {
    DrawUtils.drawAppBackground(g);
    if (categories.isEmpty()) {
      text8.drawString2(g, WAITING_MESSAGE, GameColor.WHITE_CODE, GameConstants.SCREEN_WIDTH / 2, GameConstants.SCREEN_HEIGHT / 2, GameConstants.TOP_HCENTER_ANCHOR);
    }
    if (formType.equals("program") && categories.size() != 0) {
      drawProgram(g);
    }
    if (formType.equals("phase")) {
      drawPhase(g);
    }
    if (formType.equals("PHANG_ONLINE")) {
      drawPhangOnline(g);
    }
    if (formType.equals("FOOTBALL_TAI_XIU") || formType.equals("FOOTBALL_TS") || formType.equals("FOOTBALL_KQ")) {
      drawFootballOnline(g);
    }
    if (formType.equals("DAU_GIA_NGUOC") || formType.equals("DAU_GIA_NGUOC_RESULT")) {
      drawDauGiaNguoc(g);
    }
    DrawUtils.drawTopBar(g);
    drawMenu(g);

    text8.drawString2(g, title, GameColor.WHITE_CODE, GameConstants.SCREEN_WIDTH / 2, 5, GameConstants.TOP_HCENTER_ANCHOR);
  }

  private void drawDauGiaNguoc(Graphics g) {
    int textY = dy;
    int index = 0;
    for (int i = 0; i < categories.size(); i++) {
      Category category = (Category) categories.elementAt(i);
      g.setColor(0xA9A9A9);
      g.fillRect(0, textY, GameConstants.SCREEN_WIDTH, text8.getHeight() + 5);
      text8.drawString3(g, "Tài khoản: " + category.exParam.elementAt(1), GameColor.WHITE_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      text8.drawString3(g, "Số tiền: " + category.exParam.elementAt(2) + "$", GameColor.WHITE_CODE, text8.stringWidth("Tài khoản: " + category.exParam.elementAt(1)) + 10, textY,
          GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, (String) category.exParam.elementAt(category.exParam.size() - 1), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, (String) category.exParam.elementAt(0), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, "Đặt giá: " + category.exParam.elementAt(3) + "$", GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, "Thời gian: " + category.exParam.elementAt(6), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      String status = "Đang chờ";
      textY = textY + 20;
      if (formType.equals("DAU_GIA_NGUOC")) {
        if (category.exParam.elementAt(4).equals("99")) {
          status = "Trúng";
        } else if (category.exParam.elementAt(4).equals("-99")) {
          status = "Trượt";
        } else {
          status = "Đang chờ";
        }
      } else if (formType.equals("DAU_GIA_NGUOC_RESULT")) {
        if (category.exParam.elementAt(4).equals("99")) {
          if (index == 0) {
            status = "Trúng: " + (String) category.exParam.elementAt(0);
          } else if (index == 1) {
            status = "Trúng: Thẻ cào 200K";
          } else if (index == 2) {
            status = "Trúng: Thẻ cào 100K";
          }
        } else if (category.exParam.elementAt(4).equals("-99")) {
          status = "Trượt";
        } else {
          status = "Đang chờ";
        }
      }
      text8.drawString3(g, status, GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      g.setColor(0xC0C0C0);
      g.drawLine(0, textY, GameConstants.SCREEN_WIDTH, textY);
      index++;
    }
    bottomParagraph = textY;
    if (minTextY == -1) {
      minTextY = Constants.SCREEN_HEIGHT / 2 - bottomParagraph;
    }
    text8.drawString3(g, " ", GameColor.WHITE_CODE, 0, textY + 30, Constants.TOP_LEFT_ANCHOR, scrollBar);
    scrollBar.draw(g);
  }

  private void drawFootballOnline(Graphics g) {
    int textY = dy;
    int index = 0;
    for (int i = 0; i < categories.size(); i++) {
      Category category = (Category) categories.elementAt(i);
      g.setColor(0xA9A9A9);
      g.fillRect(0, textY, GameConstants.SCREEN_WIDTH, text8.getHeight() + 5);
      text8.drawString3(g, "Tài khoản: " + category.exParam.elementAt(1), GameColor.WHITE_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      text8.drawString3(g, "Số tiền: " + category.exParam.elementAt(2) + "$", GameColor.WHITE_CODE, text8.stringWidth("Tài khoản: " + category.exParam.elementAt(1)) + 10, textY,
          GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, (String) category.exParam.elementAt(category.exParam.size() - 1), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, "Đặt cửa " + category.exParam.elementAt(0) + " " + category.exParam.elementAt(3), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, "Đặt giá: " + category.exParam.elementAt(5) + "$", GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, "Thời gian: " + category.exParam.elementAt(6), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      String status = "Đang chờ";
      if (category.exParam.elementAt(4).equals("99")) {
        status = "Trúng";
      } else if (category.exParam.elementAt(4).equals("-99")) {
        status = "Trượt";
      } else {
        status = "Đang chờ";
      }
      text8.drawString3(g, "Tình trạng: " + status, GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      g.setColor(0xC0C0C0);
      g.drawLine(0, textY, GameConstants.SCREEN_WIDTH, textY);
      index++;
    }
    bottomParagraph = textY;
    if (minTextY == -1) {
      minTextY = Constants.SCREEN_HEIGHT / 2 - bottomParagraph;
    }
    text8.drawString3(g, " ", GameColor.WHITE_CODE, 0, textY + 30, Constants.TOP_LEFT_ANCHOR, scrollBar);
    scrollBar.draw(g);
  }

  private void drawPhangOnline(Graphics g) {
    int textY = dy;
    int index = 0;
    for (int i = 0; i < categories.size(); i++) {
      Category category = (Category) categories.elementAt(i);
      g.setColor(0xA9A9A9);
      g.fillRect(0, textY, GameConstants.SCREEN_WIDTH, text8.getHeight() + 5);
      text8.drawString3(g, "Tài khoản: " + category.exParam.elementAt(1), GameColor.WHITE_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      text8.drawString3(g, "Số tiền: " + category.exParam.elementAt(2) + "$", GameColor.WHITE_CODE, text8.stringWidth("Tài khoản: " + category.exParam.elementAt(1)) + 10, textY,
          GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, (String) category.exParam.elementAt(category.exParam.size() - 1), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, category.exParam.elementAt(0) + " " + category.exParam.elementAt(3), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, "Đặt giá: " + category.exParam.elementAt(5) + "$", GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      text8.drawString3(g, "Thời gian: " + category.exParam.elementAt(6), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      String status = "Đang chờ";
      if (category.exParam.elementAt(4).equals("99")) {
        status = "Trúng";
      } else if (category.exParam.elementAt(4).equals("-99")) {
        status = "Trượt";
      } else {
        status = "Đang chờ";
      }
      text8.drawString3(g, "Tình trạng: " + status, GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR, scrollBar);
      textY = textY + 20;
      g.setColor(0xC0C0C0);
      g.drawLine(0, textY, GameConstants.SCREEN_WIDTH, textY);
      index++;
    }
    bottomParagraph = textY;
    if (minTextY == -1) {
      minTextY = Constants.SCREEN_HEIGHT / 2 - bottomParagraph;
    }
    text8.drawString3(g, " ", GameColor.WHITE_CODE, 0, textY + 30, Constants.TOP_LEFT_ANCHOR, scrollBar);
    scrollBar.draw(g);
  }

  private void drawPhase(Graphics g) {
    int textY = dy;
    int index = 0;
    for (int i = 0; i < categories.size(); i++) {
      Category category = (Category) categories.elementAt(i);
      if (categoryIndex == index) {
        g.setColor(0x53A4CF);
        g.fillRect(0, textY, GameConstants.SCREEN_WIDTH, text8.getHeight() + 50);
        for (int j = 0; j < category.exParam.size(); j++) {
          text8.drawString2(g, (String) category.exParam.elementAt(j), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR);
          textY = textY + 20;
        }
      } else {
        for (int j = 0; j < category.exParam.size(); j++) {
          text8.drawString2(g, (String) category.exParam.elementAt(j), GameColor.YELLOW_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR);
          textY = textY + 20;
        }
      }
      textY = textY + 20;
      if (categoryIndex == index) {
        g.setColor(0x53A4CF);
        g.fillRect(0, textY, GameConstants.SCREEN_WIDTH, text8.getHeight() + 5);
        if (category.status == 1) {
          text8.drawString2(g, "Đang diễn ra", GameColor.WHITE_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR);
        } else {
          text8.drawString2(g, "Đã kết thúc", GameColor.WHITE_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR);
        }
        text8.drawString2(g, "Chi tiết >>", GameColor.WHITE_CODE, GameConstants.SCREEN_WIDTH - 5, textY, GameConstants.TOP_RIGHT_ANCHOR);
      } else {
        if (category.status == 1) {
          text8.drawString2(g, "Đang diễn ra", GameColor.WHITE_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR);
        } else {
          text8.drawString2(g, "Đã kết thúc", GameColor.WHITE_CODE, 5, textY, GameConstants.TOP_LEFT_ANCHOR);
        }
        text8.drawString2(g, "Chi tiết >>", GameColor.WHITE_CODE, GameConstants.SCREEN_WIDTH - 5, textY, GameConstants.TOP_RIGHT_ANCHOR);
      }
      textY = textY + 20;
      g.setColor(0xC0C0C0);
      g.drawLine(0, textY, GameConstants.SCREEN_WIDTH, textY);
      index++;
    }
  }

  private void drawProgram(Graphics g) {
    int textY = dy;
    int index = 0;
    for (int i = 0; i < categories.size(); i++) {
      Category category = (Category) categories.elementAt(i);
      g.drawImage(category.image, 0, textY, GameConstants.TOP_LEFT_ANCHOR);
      if (!category.hasChild) {
        text8.drawString2(g, category.name, GameColor.YELLOW_CODE, category.image.getWidth() + 5, textY + category.image.getHeight() / 50, GameConstants.TOP_LEFT_ANCHOR);
      } else {
        text8.drawString2(g, category.name, GameColor.YELLOW_CODE, category.image.getWidth() + 5, textY + category.image.getHeight() / 3, GameConstants.TOP_LEFT_ANCHOR);
      }
      if (categoryIndex == index) {
        g.setColor(0x53A4CF);
        g.fillRect(0, textY - 7, GameConstants.SCREEN_WIDTH, category.image.getHeight() + 25);
        g.drawImage(category.image, 0, textY, GameConstants.TOP_LEFT_ANCHOR);
        if (!category.hasChild) {
          text8.drawString2(g, category.name, GameColor.YELLOW_CODE, category.image.getWidth() + 5, textY + category.image.getHeight() / 50, GameConstants.TOP_LEFT_ANCHOR);
        } else {
          text8.drawString2(g, category.name, GameColor.YELLOW_CODE, category.image.getWidth() + 5, textY + category.image.getHeight() / 3, GameConstants.TOP_LEFT_ANCHOR);
        }
      }
      if (!category.hasChild) {
        text8.drawString2(g, "Chi tiết >>", GameColor.WHITE_CODE, GameConstants.SCREEN_WIDTH - 5, textY + category.image.getHeight(), GameConstants.TOP_RIGHT_ANCHOR);
      }
      g.setColor(0xC0C0C0);
      g.drawLine(0, textY - 7, GameConstants.SCREEN_WIDTH, textY - 7);
      textY = textY + category.image.getHeight() + 25;
      index++;
    }
    bottomParagraph = textY;
  }

  private void drawMenu(Graphics g) {
    DrawUtils.getBottomBar(_manager).setRightLabel("Trở về");
  }

  public void onRecieveData(DataPackage dataPackage) {
    GameGlobal.systemCanvas.hideAlert();
    int header = dataPackage.getHeader();
    Category category = null;
    MapDataPackage mapDataPackage = MapDataPackage.getMapPackage(dataPackage);
    formType = mapDataPackage.popString("type");
    switch (header) {
    case VOTING_LIST_RESPONSE:
      category = new Category();
      category.exParam.addElement(mapDataPackage.getString("votingObject"));
      category.exParam.addElement(mapDataPackage.getString("user"));
      category.exParam.addElement(mapDataPackage.getString("money"));
      category.exParam.addElement(mapDataPackage.getString("value"));
      category.exParam.addElement(mapDataPackage.getString("status"));
      category.exParam.addElement(mapDataPackage.getString("betMoney"));
      category.exParam.addElement(mapDataPackage.getString("created"));
      category.exParam.addElement(mapDataPackage.getString("phaseId"));
      category.hasChild = false;
      categories.addElement(category);
      break;
    case VOTING_LIST_HISTORY_RESPONSE:
    case DAU_GIA_NGUOC_RESULT_RESPONSE:
      if (formType.equals("DAU_GIA_NGUOC")) {
        DrawUtils.getBottomBar(_manager).setLeftLabel("DS trúng thưởng");
      } else {
        DrawUtils.getBottomBar(_manager).setLeftLabel(null);
      }
      String status = mapDataPackage.getString("status");
      if (status.equals("-1")) {
        Global.alert.showAlert2(this, GameAlert.OK_TYPE,  "Chưa có dư liệu danh mục này" , -1);
        category = new Category();
        category.exParam.addElement("");
        category.exParam.addElement("");
        category.exParam.addElement("");
        category.exParam.addElement("");
        category.exParam.addElement("");
        category.exParam.addElement("");
        category.exParam.addElement("");
        category.exParam.addElement(mapDataPackage.getString("phaseId"));
        category.exParam.addElement("");
        category.hasChild = false;
        categories.addElement(category);
        return;
      }
      category = new Category();
      category.exParam.addElement(mapDataPackage.getString("votingObject"));
      category.exParam.addElement(mapDataPackage.getString("user"));
      category.exParam.addElement(mapDataPackage.getString("money"));
      category.exParam.addElement(mapDataPackage.getString("value"));
      category.exParam.addElement(mapDataPackage.getString("status"));
      category.exParam.addElement(mapDataPackage.getString("betMoney"));
      category.exParam.addElement(mapDataPackage.getString("created"));
      category.exParam.addElement(mapDataPackage.getString("phaseId"));
      category.exParam.addElement(mapDataPackage.getString("phaseName"));
      category.hasChild = false;
      categories.addElement(category);
      break;
    }
  }

  private void request(int header, Vector parameters1) {
    DataPackage dataPackage = DataPackage.createDataPackage1(header);
    for (int i = 0; i < parameters1.size(); i++) {
      dataPackage.putString(parameters1.elementAt(i).toString());
    }
    Global.appClient.write(dataPackage);
    logAction.put(String.valueOf(currentAction), buildLogAction(header, parameters1));
  }

  private String buildLogAction(int requestType, Vector parameters1) {
    StringBuffer sb = new StringBuffer();
    sb.append(String.valueOf(requestType));
    sb.append(",");
    for (int i = 0; i < parameters1.size(); i++) {
      sb.append(parameters1.elementAt(i).toString());
      sb.append(",");
    }
    if (sb.toString().endsWith(",")) {
      sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
  }

  public void keyRepeated(int keyCode) {
    switch (keyCode) {
    case Key.DOWN:
      if (formType.equals("PHANG_ONLINE")) {
        if (scrollBar.canScrollUp()) {
          dy -= 10;
        }
      }
      break;
    case Key.UP:
      if (formType.equals("PHANG_ONLINE")) {
        if (scrollBar.canScrollDown()) {
          dy += 10;
        }
      }
    default:
      break;
    }
  }

  public void keyReleased(int keyCode) {
    switch (keyCode) {
    case Key.LEFT:
      break;
    case Key.DOWN:
      if (!categories.isEmpty()) {
        if (formType.equals("program") || formType.equals("phase") || formType.equals("voting")) {
          if (categoryIndex < categories.size() - 1) {
            categoryIndex++;
          }
        }
      }
      if (bottomParagraph > (DrawUtils.getTopBarHeight() + GameConstants.SCREEN_HEIGHT / 2)) {
        if (formType.equals("phase") || formType.equals("voting") || formType.equals("PHANG_ONLINE") || formType.equals("DAU_GIA_NGUOC") || formType.equals("FOOTBALL_TAI_XIU")
            || formType.equals("FOOTBALL_TS") || formType.equals("FOOTBALL_KQ") || formType.equals("DAU_GIA_NGUOC_RESULT")) {
          if (scrollBar.canScrollUp()) {
            dy -= 10;
          }
        }
      }
      break;
    case Key.RIGHT:
      break;
    case Key.UP:
      if (!categories.isEmpty()) {
        if (formType.equals("program") || formType.equals("phase") || formType.equals("voting")) {
          if (categoryIndex > 0) {
            categoryIndex--;
          } else if (categoryIndex == 0) {
          }
        }
      }
      if (dy <= defaultY) {
        if (formType.equals("program") || formType.equals("voting") || formType.equals("phase") || formType.equals("PHANG_ONLINE") || formType.equals("DAU_GIA_NGUOC")
            || formType.equals("FOOTBALL_TAI_XIU") || formType.equals("FOOTBALL_TS") || formType.equals("FOOTBALL_KQ") || formType.equals("DAU_GIA_NGUOC_RESULT")) {
          if (scrollBar.canScrollDown()) {
            dy += 10;
          }
        }
      } else {
        dy = DrawUtils.getTopBarHeight();
      }
      break;
    case Key.SOFT_RIGHT:
      if (currentAction > 1) {
        clearCategory();
        back();
      } else {
        Global.nextState(FrmGroupBongDaXoSo.instance(), null);
      }
      break;
    case Key.SOFT_LEFT:
      if (formType.equals("DAU_GIA_NGUOC")) {
        currentAction++;
        Category category = (Category) categories.elementAt(0);
        Vector param = new Vector();
        param.addElement(category.exParam.elementAt(category.exParam.size() - 2));
        request(DAU_GIA_NGUOC_RESULT_REQUEST, param);
        clearCategory();
      }
      break;
    }
  }

  public void alertEventPerform(int alertType, int eventType, int alertId) {
    // if (alertId == -1) {
    // Global.nextState(Global.systemCanvas.lastState, parameters);
    // }
  }

  private void back() {
    currentAction--;
    String values = (String) logAction.get(String.valueOf(currentAction));
    StringArray requestParams = GameStringUtils.split(values, ",");
    int request = NumberUtil.parseInt(requestParams.get(0));
    Vector param = new Vector();
    for (int i = 1; i < requestParams.len(); i++)
      param.addElement(requestParams.get(i));
    request(request, param);
    Global.alert.showAlert2(this, GameAlert.LOADING_WITH_NO_BUTTON_TYPE, "Đang tải...", 99).setAlertTimeOut(10000);
  }

  private void clearCategory() {
    categories.removeAllElements();
    categoryIndex = 0;
    dy = DrawUtils.getTopBarHeight() + 1;
    Global.alert.showAlert2(this, GameAlert.LOADING_WITH_NO_BUTTON_TYPE, "Đang tải...", 99).setAlertTimeOut(10000);
  }

  public void destroy() {
    logAction = null;
    currentAction = 1;
    formType = null;
    text8 = null;
    categories = null;
    currentAction = 1;
    dy = 0;
    parameters = null;
    title = null;
  }
}
